<template>
    <div class="agentRentalList hasFoot ">
        <HeaderNav3 :activeIndex="activeIndex"></HeaderNav3>
        <Contact></Contact>
        <Ad></Ad>
        <div class="agentRentalList-item wrap">
            <div class="title">
                <h1>
                    為你服務的專業代理
                </h1>
            </div>
            <div class="item1" >
                <el-table 
                  :data="items"
                  style="width: 100%"
                  align="center" 
                  >
                  <el-table-column
                    prop="published_time"
                    label="發佈時間"
                    width="150"
                    align="center"
                    class-name="a">
                  </el-table-column>
                  <el-table-column
                    prop="loupan_name"
                    label="樓盤名稱"
                    width="180"
                    align="center">
                  </el-table-column>
                  <el-table-column 
                    prop="post_floor"
                    label="樓層"
                    width="135"
                    align="center">
                  </el-table-column>
                   <el-table-column 
                    prop="post_seat"
                    label="座數"
                    width="135"
                    align="center">
                  </el-table-column>
                   <el-table-column 
                    prop="post_acreage"
                    label="尺數"
                    width="135"
                    align="center">
                  </el-table-column>
                   <el-table-column 
                    prop="post_sell"
                    label="價格"
                    width="135"
                    align="center">
                  </el-table-column>
                  <el-table-column 
                    prop="post_sell2"
                    label="尺價"
                    width="135"
                    align="center">
                  </el-table-column>
                    <el-table-column label="詳細內容" inline-template align="center">
                      <el-button @click.native="showDetail(row)">
                     詳情</el-button>
                    </el-table-column>
                </el-table>
            </div>
            <div class="item2">
                <el-pagination
                    layout="prev, pager, next"
                    @current-change="handleCurrentChange"
                    :total="totalCount">
                </el-pagination>
            </div>
        </div>
    </div>
        
</template>

<script>
import HeaderNav3 from "@/components/HeaderNav3.vue"
import Contact from '@/components/Contact.vue'
import Ad from '@/components/Ad.vue'

import { V1_SPACE } from "@/config/api"
export default {
	components:{
        Contact,
        Ad,
        HeaderNav3
	},
    computed:{
        
        },

    activated(){ 
        this.$store.commit("IS_SHOW_ALERT",true);
        if(this.$route.query.type!=this.type){
            this.getData();
            this.type=this.$route.query.type;
        }
    },   
    data(){
       
        return{
           "items":[],
           "totalCount":0,
            "currentPage":0,
            "activeIndex":"2",
            "type":this.$route.query.type,
            "id":this.$route.query.id,
       }
    },
    methods:{
        getData(){
            this.$http.get(V1_SPACE+this.$route.query.id+"/"+(this.currentPage|0)+"/"+10+"/"+this.$route.query.type,{
            }).then(res=>{
                if(res.data.success){
                    this.items=res.data.infor.listItems;
                    this.totalCount = Math.ceil(res.data.infor.totalCount/10)*10;
                    //时间转换成年月份
                    this.items.map((item) => {

                        var da = item.published_time*1000;
                        da = new Date(da);
                        var year = da.getFullYear()+'年';
                        var month = da.getMonth()+1+'月';
                        var date = da.getDate()+'日';
                        item.published_time=[year,month,date].join('');
                    })
                   
                }
            })
        },
        handleCurrentChange(page) {
            this.currentPage = page-1;
            this.getData();
        }, 
        showDetail(row){
           this.$router.push({
                "path": "/spaceDetails",
                "query":{
                    "id":row.id
                }
            });
        }
    },
    mounted(){ 
         this.getData();
    },
}
</script>
<style lang="scss">
    @import "../style/agentRentalList";
</style>